package com.fdd.spring.aop.aspectj;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Order(1)
@Aspect  //切面类
@Component  //注入到容器
public class SmartAnimalAspect3 {

    @Pointcut(value = "execution(public double com.fdd.spring.aop.aspectj.SmartAnimalable.getSum(double, double))")
    public void myPiontCut(){

    }
    /**
     * 前置通知
     * @param joinPoint
     */
//    @Before(value = "execution(public double SmartAnimalable.*(double, double))")
    @Before(value = "myPiontCut()")
    public static void f1(JoinPoint joinPoint){
        joinPoint.getSignature();//获取方法签名
        System.out.println("SmartAnimalable3-FddAop-方法执行前-日志-方法名-" + joinPoint.getSignature() + "-参数：" + Arrays.toString(joinPoint.getArgs()));
    }

    //返回通知，它在目标方法正常执行完成并返回结果后触发
//    @AfterReturning(value = "execution(public double com.fdd.spring.aop.aspectj.SmartAnimalable.getSum(double, double))", returning = "result")
    @AfterReturning(value = "myPiontCut()", returning = "result")
    public void f2(JoinPoint joinPoint,Object result){
        System.out.println("SmartAnimalable3-FddAop-方法执行后-日志-方法名-" + joinPoint.getSignature() + "-参数：" + Arrays.toString(joinPoint.getArgs()) + "-结果：" + result);
    }

    @AfterThrowing(value = "execution(public double com.fdd.spring.aop.aspectj.SmartAnimalable.getSum(double, double))", throwing = "ex")
    public void f3(JoinPoint joinPoint, Exception ex){
        System.out.println("SmartAnimalable3-FddAop-方法执行异常-日志-方法名-" + joinPoint.getSignature() + "-参数：" + Arrays.toString(joinPoint.getArgs()) + "-异常：" + ex);
    }

    @After(value = "execution(public double com.fdd.spring.aop.aspectj.SmartAnimalable.getSum(double, double))")
    public void f4(JoinPoint joinPoint){
        System.out.println("SmartAnimalable3-FddAop-方法执行后最终通知-日志-方法名-" + joinPoint.getSignature() + "-参数：" + Arrays.toString(joinPoint.getArgs()));
    }



    @Before(value = "execution(* Car.run())")
    public static void ok(JoinPoint joinPoint){
        joinPoint.getSignature();//获取方法签名
        System.out.println("FddAop-方法执行前-日志-方法名-" + joinPoint.getSignature() + "-参数：" + Arrays.toString(joinPoint.getArgs()));
    }
}
